/*
 * @Author: shiliu
 * @Date: 2022-01-18 14:36:23
 * @LastEditTime: 2022-01-20 14:16:21
 * @LastEditors: shiliu
 * @Description:
 */
#ifndef __OTA_H__
#define __OTA_H__

#include "stm32f4xx.h"

/* FLASH Zone Table */
#define FLASH_APP_1_ADDR    0x08008000U /* 224k: 0x0800 8000 - 0x0803 FFFF*/
#define FLASH_APP_2_ADDR    0x08040000U /* 256k: 0x0804 0000 - 0x0807 FFFF*/

#define FLASH_OTA_FLAG_ADDR 0x0807FFF0U
#define OTA_START_FLAG      0x5AU
#define OTA_OVER_FLAG       0x01U

#define FLASH_BIN_SIZE_ADDR 0x0807FFF4U


void set_ota_start_flag(void);
void ota_start(void);

int8_t erase_app2(void);

int8_t flash_erase_sector(uint32_t sector);
int8_t flash_program_word(uint32_t flash_addr, uint32_t *data, uint32_t word_size);
int8_t flash_program_byte(uint32_t flash_addr, const unsigned char *data, uint32_t byte_size);

#endif /* __OTA_H__ */
